// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-aggregate-error
description: >
  Abrupt completions of ToString(Symbol message)
info: |
  AggregateError ( errors, message )

  ...
  5. If message is not undefined, then
    a. Let msg be ? ToString(message).
    b. Perform ! CreateMethodProperty(O, "message", msg).
  6. Return O.
features: [AggregateError, Symbol, Symbol.toPrimitive]
---*/

function Test() {
    var case1 = Symbol();

    assert.throws(TypeError, () => {
      new AggregateError([], case1);
    }, 'toPrimitive');

    var case2 = {
      [Symbol.toPrimitive]() {
        return Symbol();
      },
      toString() {
        throw new Test262Error();
      },
      valueOf() {
        throw new Test262Error();
      }
    };

    assert.throws(TypeError, () => {
      new AggregateError([], case2);
    }, 'from ToPrimitive');
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}
